﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using ARS.PublicTool.WebHelper.WebPage;

namespace ARS.Control.Interface
{
    public class DefaultDialog : Interface.IDialog
    {

        public DefaultDialog()
        {
            //this.parent = "parent.";
        }

        private Page page;
        private Type type;
        public DefaultDialog(Page page, Type type)
        {
            this.page = page;
            this.type = type;
            //this.RegisterClientScript(page,type);
        }

        //protected string parent=null;
        //public DefaultDialog(bool isParent)
        //{
        //    if (isParent)
        //    {
        //        this.parent = "parent.";
        //    }            
        //}

        public virtual void RegisterClientScript(Page page, Type type)
        {
            ARS.PublicTool.WebHelper.WebPage.PageAddResource.AddCss(page,type,ARS.Control.Attributes.ResourcePath.EasyDialog.css);
            page.ClientScript.RegisterClientScriptResource(type, ARS.Control.Attributes.ResourcePath.EasyDialog.js);
        }

        public virtual string ShowInfo(Page page, Type type,string message, string title = "提示")
        {
            this.RegisterClientScript(page, type);

            return string.Format("easyDialog.open({{container : {{header : '{0}',content : '{1}'}},drag : false  }});", title, message);
        }

//        public string ShowInfo(string message, string title = "提示")
//        {
//            return null;
//        }

        public virtual string ShowAddInfo(Page page, Type type, int id, bool flag, string message = null)
        {
            this.RegisterClientScript(page, type);
            if (flag)
            {
                return "easyDialog.open({container : {content : '添加成功'},autoClose : 2000});";
            }
            else
            {
                //StringBuilder sb = new StringBuilder();
                //sb.Append(ScriptHelper.GetScriptStr("alert(12)"));
                //return sb.ToString();
                return   "easyDialog.open({container : {content : '添加失败'},autoClose : 2000});";
            }
        }

        public virtual string ShowUpdateInfo(Page page, Type type, int id, bool flag, string message = null)
        {
            this.RegisterClientScript(page, type);
            if (flag)
            {
                return   "easyDialog.open({container : {content : '修改成功'},autoClose : 2000});";
            }
            else
            {
                return   "easyDialog.open({container : {content : '修改失败'},autoClose : 2000});";
            }
        }

        //private string GetDataPaging_DelConfirm(string str)
        //{
        //    return string.Format("function DeleteData(id) {}");
        //}

        public virtual string DataPaging_DelConfirm(Page page, Type type)
        {
            this.RegisterClientScript(page, type);
            StringBuilder sb = new StringBuilder();
            sb.Append("function btnFn() { DataPaging_Operat.DeleteData(id);}easyDialog.open({container: {header: '删除',content: '确认删除吗？',yesFn: btnFn,noFn: true},overlay: true});");

            return sb.ToString();
        }

        public virtual string TreeListView_DelConfirm(Page page, Type type)
        {
            this.RegisterClientScript(page,type);

           // page.ClientScript.RegisterClientScriptResource(type, ARS.Control.Attributes.ResourcePath.TreeListView.js);

            StringBuilder sb = new StringBuilder();
            sb.Append("function btnFn() { TreeListView_Operat.DeleteData(id);}easyDialog.open({container: {header: '删除',content: '确认删除吗？',yesFn: btnFn,noFn: true},overlay: true});");

            return sb.ToString();
        }

        public void ShowInfo(string message, string title = "提示")
        {
            page.ClientScript.RegisterStartupScript(type, "test",
                ARS.PublicTool.WebHelper.WebPage.ScriptHelper.GetScriptStr(this.ShowInfo(page, type, message, title)));
        }

        public void ShowAddInfo(int id, bool flag, string message = null)
        {
            page.ClientScript.RegisterStartupScript(type, "test",
                ARS.PublicTool.WebHelper.WebPage.ScriptHelper.GetScriptStr(this.ShowAddInfo(page, type, id, flag, message)));
        }

        public void ShowUpdateInfo(int id, bool flag, string message = null)
        {
            page.ClientScript.RegisterStartupScript(type, "test",
                ARS.PublicTool.WebHelper.WebPage.ScriptHelper.GetScriptStr(this.ShowUpdateInfo(page, type, id, flag, message)));
        }

//        public string DataPaging_DelConfirm()
//        {
//            return this.DataPaging_DelConfirm(page, type);
//        }
//
//        public string TreeListView_DelConfirm()
//        {
//            throw new NotImplementedException();
//        }
    }
}
